package org.anupta.game.utils.others;

import org.anupta.game.main.Main;
import org.anupta.game.utils.others.EnumsInfo.Population;
import org.anupta.game.utils.others.EnumsInfo.State;
import org.anupta.game.utils.others.EnumsInfo.Type;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;

public class Config {
	public static int TIME_OUT = (15*60*1000);//Minute
	public static int TIME_SAVE = (3*1000);//Seconds
	public static String MOTD = null;
	public static String MOTD_COLOR = null;
	//Sql
    public static String DRIVER = "com.mysql.jdbc.Driver";
    public static String[] LOGIN = {
    	"jdbc:mysql://localhost/anupta",
    	"baskwo",
    	"colacoka"
    };
    public static String[] LOGIN_GAME = {
    	"jdbc:mysql://localhost/anupta_game",
    	"baskwo",
    	"colacoka"
    };
    
    //Game
    public static byte ID = 1;
    public static State STATE = State.OFFLINE;//Online when Connect sended, but can be changed
    public static Type TYPE = Type.CLASSIC;
    public static Population POPULATION = Population.FULL;
    public static String GAME_IP = "127.0.0.1";
    public static int GAME_PORT = 5556;
    
    //Inter
    public static String INTER_IP = "127.0.0.1";
    public static int INTER_PORT = 666;//Mouhahahahaahah (6) :D
    
    //Other
    public static int MAX_CHARAC = 5;
    
    public static void readConfig(String filePath){
    	XMLConfiguration xml = new XMLConfiguration();
    	xml.setListDelimiter(';');
    	xml.setFileName(filePath);
		try {
			xml.load();
		} catch (ConfigurationException e) {
			Main.err.write(e);
		}
    	parseXML(xml);
    }
    private static void parseXML(XMLConfiguration xml){
    	TIME_OUT = (xml.getInt("server.timeOut",TIME_OUT)*60*1000);
    	TIME_SAVE = (xml.getInt("server.saveTime", TIME_SAVE)*1000);
    	MOTD = xml.getString("server.motd");
    	MOTD_COLOR = xml.getString("server.motdColor");
    	
    	DRIVER = xml.getString("sql.driver", DRIVER);
    	LOGIN[0] = xml.getString("sql.url", LOGIN[0]);
    	LOGIN[1] = xml.getString("sql.user", LOGIN[1]);
    	LOGIN[2] = xml.getString("sql.pass", LOGIN[2]);
    	LOGIN_GAME[0] = xml.getString("sql.game.url", LOGIN_GAME[0]);
    	LOGIN_GAME[1] = xml.getString("sql.game.user", LOGIN_GAME[1]);
    	LOGIN_GAME[2] = xml.getString("sql.game.pass", LOGIN_GAME[2]);
    	
    	POPULATION = Population.get(xml.getByte("server.game"+ID+".pop",POPULATION.getPopulation()));
    	TYPE = Type.get(xml.getByte("server.game"+ID+".type",TYPE.getType()));
    	GAME_IP = xml.getString("server.game"+ID+".ip",GAME_IP);
    	GAME_PORT = xml.getInt("server.game"+ID+".port",GAME_PORT);
    	
    	INTER_IP = xml.getString("server.inter.ip", INTER_IP);
    	INTER_PORT = xml.getInt("server.inter.port", INTER_PORT);
    	
    	MAX_CHARAC = xml.getInt("server.game"+ID+".maxCharac",MAX_CHARAC);
    }
}
